import { Suspense } from "react";   
import { Route, Switch, NavLink, Link,Redirect } from 'react-router-dom'
let RouterView = (props)=>{
    // console.log(props);
    let {RouterList} = props
    console.log(RouterList);
    let routerlist = RouterList.filter(item=>!item.to)
    console.log(routerlist);
    let rederict = RouterList.filter(item=>item.to)[0]
    console.log(rederict);
    return (
        <Suspense fallback={<div>...加载中</div>}>
            <Switch>   
                {
                    routerlist && routerlist.length ? routerlist.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                                if (item.children) {
                                    return <item.component {...routerProps} child={item.children}></item.component>
                                }
                                 return <item.component {...routerProps}></item.component>
                        }}></Route>
                    }):"暂无路由"
                }
                {
                    rederict?<Redirect from={rederict.from} to={rederict.to}></Redirect>:"暂无重定向"
                }
            </Switch>
        </Suspense>
    )
}
export default RouterView